package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	accessToken := "80_0vvhq6vBk-r0_d9Bp1TRbFB-Eei8j0SMN-qzbjaA7SYRu2NONgubKP8KvuGZ6DDQMcEGe2xh1axavUl-2iTKJRw9kuUHBJa2LuZAR-Sgep-KThHu77mpuYM2r0IQVAiAEALQV"
	url := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=%s", accessToken)

	// 创建请求体
	requestBody := map[string]interface{}{
		"type":   "image",
		"offset": 0,
		"count":  1,
	}

	// 将请求体编码为JSON
	jsonData, err := json.Marshal(requestBody)
	if err != nil {
		fmt.Println("Error marshaling JSON:", err)
		return
	}

	// 创建POST请求
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}

	// 设置请求头
	req.Header.Set("Content-Type", "application/json")

	// 发送请求
	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Error sending request:", err)
		return
	}
	defer resp.Body.Close()

	// 读取响应
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response:", err)
		return
	}

	// 打印响应
	fmt.Println("Response Status:", resp.Status)
	fmt.Println("Response Body:", string(body))
	//Response Status: 200 OK
	//Response Body: {"item":[
	//{"media_id":"EdiS0wbrTMmoD_ZQZOruhNLjw4s6gwGAAMPBrbidqm1Ob8DqoK-3DC6O0cKw5ara" // 互联网大厂的图片的id
	//,"name":"封面.jpg","update_time":1715872136,"url":"https:\/\/mmbiz.qpic.cn\/sz_mmbiz_jpg\/LQ4lXCibEc76SjswXpmhFLFlX1hFM1yAFO17LN7SsiacyUib75fRJicCClVSo33282RQmxrkpicbxzlx57gkDYy5hWg\/0?wx_fmt=jpeg&from=appmsg","tags":[]}],"total_count":3,"item_count":1}

}
